package com.badibadi.mail;

import java.util.HashMap;
import java.util.Map;

import com.badibadi.infos.PayUserContactShow1Model;
import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;

import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**常熟已经改
 * 该界面是答方等待问方同不同意款项
 * @author Administrator
 * *
 * 答方：等待问方同意自己的款项
 * 问方：选择是否同意该款项
 * 设定完成后： 同意-》Mail13_6Activity（同意付款，但是还没有付款）
 *         拒绝-》Mail9_11_12Activity（拒绝支付）
 */
public class Mail67Activity extends Mail245Activity {
	protected static final String TAG = "Mail67Activity";
	//如果是从Mail245中过来的设定为true
//	private boolean Mail245=false;
	AlertDialog al_sheding;
	
	private boolean isAgree=true;//是否同意
	public Handler mhandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(Mail67Activity.this);
				try {
					Utils.showMessage(Mail67Activity.this, getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2:
				Utils.ExitPrgress(Mail67Activity.this);
				try {
					Utils.showMessage(Mail67Activity.this, getResources().getString(R.string.wx_send_success));
					if(isAgree==true)
					{
						
//<<<<<<< .mine
//						PayUtils.fenrui(Mail67Activity.this,
//								payUserContactShow1Model.getContent_id(),
//								payUserContactShow1Model.getUid(), ""
//										+ payUserContactShow1Model
//												.getZhannei_usercontact()
//												.get(0).getFees());
						Intent intent=new Intent(Mail67Activity.this,Mail13_6Activity.class);
						intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
						startActivity(intent);
						finish();
//=======
//						PayUtils.fenrui(Mail67Activity.this,
//								payUserContactShow1Model.getContent_id(),
//								payUserContactShow1Model.getUid(), ""
//										+ payUserContactShow1Model
//												.getZhannei_usercontact()
//												.get(0).getFees());
//						Intent intent=new Intent(Mail67Activity.this,Mail13_6Activity.class);
//						intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
//						startActivity(intent);
//						finish();
//>>>>>>> .r291
					}
					else
					{
						Intent intent=new Intent(Mail67Activity.this,Mail9_11_12Activity.class);
						intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
						startActivity(intent);
						finish();
					}
				
					
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 3:
				Utils.ExitPrgress(Mail67Activity.this);
				try {
					Utils.showMessage(Mail67Activity.this, getResources().getString(R.string.wx_send_false));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 4:
				Utils.ExitPrgress(Mail67Activity.this);
				try {
					Utils.showMessage(Mail67Activity.this, getResources().getString(R.string.wx_send_false));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
	
			default:
				break;
			}
		}

	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_mail67);
		
//		payUserContactShow1Model=(PayUserContactShow1Model) getIntent().getSerializableExtra("payUserContactShow1Model");
	}

	@Override
	protected void DongTaiPeiZhi() {
		// TODO Auto-generated method stub
//		Mail245=getIntent().getBooleanExtra("Mail245",false);
		TextView tishi=(TextView) this.findViewById(R.id.tishi);
		tishi.setText(getResources().getString(R.string.wx_zhixunfei_kuohao));
		tishi.setVisibility(View.VISIBLE);
		if(rank.equals("answerer"))
		{
			Button shedingzhixunfei=(Button)this.findViewById(R.id.shedingzhixunfei);
			shedingzhixunfei.setText(getResources().getString(R.string.wx_chakan_zhixunfei));
			shedingzhixunfei.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					LayoutInflater inflater=LayoutInflater.from(Mail67Activity.this);
		            View view=inflater.inflate(R.layout.chakanzhixunfei, null);

		            //支付宝手续费
		            TextView alipay_charge=(TextView)view.findViewById(R.id.alipay_charge);
//		               
		            alipay_charge.setText(""+payUserContactShow1Model.getAlipay_charge());
		            //达人
		            TextView expert_charge=(TextView)view.findViewById(R.id.expert_charge);
		            expert_charge.setText(""+payUserContactShow1Model.getExpert_charge());
		            //一般用户
		            TextView member_charge=(TextView)view.findViewById(R.id.member_charge);
		            member_charge.setText(""+payUserContactShow1Model.getMember_charge());
		            //显示的费用
		            TextView et_feiyong=(TextView)view.findViewById(R.id.feiyong);
		            et_feiyong.setText(""+payUserContactShow1Model.getZhannei_usercontact().get(0).getFees());
		            //退款日
		            TextView replay_limit_time=(TextView)view.findViewById(R.id.replay_limit_time);
		            replay_limit_time.setText(""+payUserContactShow1Model.getReplay_limit_time());
//		            et_feiyong.setText(); 
					al_sheding=new AlertDialog.Builder(Mail67Activity.this).setView(view).show();
				}
			});
			shedingzhixunfei.setVisibility(View.VISIBLE);
			this.findViewById(R.id.delete).setVisibility(View.GONE);
		}
		else //这是问方开始同意或者不同意这些款项
		{
			Button shedingzhixunfei=(Button)this.findViewById(R.id.shedingzhixunfei);
			shedingzhixunfei.setText(getResources().getString(R.string.wx_chakan_zhixunfei));
			shedingzhixunfei.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					LayoutInflater inflater=LayoutInflater.from(Mail67Activity.this);
		            View view=inflater.inflate(R.layout.chakanzhixunfei_settongyi_or_no_tongyi, null);

		            //支付宝手续费
		            TextView alipay_charge=(TextView)view.findViewById(R.id.alipay_charge);
		            alipay_charge.setText(""+payUserContactShow1Model.getAlipay_charge());
		            //达人
		            TextView expert_charge=(TextView)view.findViewById(R.id.expert_charge);
		            expert_charge.setText(""+payUserContactShow1Model.getExpert_charge());
		            //一般用户
		            TextView member_charge=(TextView)view.findViewById(R.id.member_charge);
		            member_charge.setText(""+payUserContactShow1Model.getMember_charge());
		            //显示的费用
		            TextView et_feiyong=(TextView)view.findViewById(R.id.feiyong);
		            et_feiyong.setText(""+payUserContactShow1Model.getZhannei_usercontact().get(0).getFees());
		            //拒绝
		            Button quxiao=(Button)view.findViewById(R.id.quxiao);
		            quxiao.setOnClickListener(new View.OnClickListener() {
						
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
//							Intent intent=new Intent(Mail67Activity.this,Mail9_11_12Activity.class);
//							intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
//							startActivity(intent);
							agree(payUserContactShow1Model.getZhannei_Id(), Utils.getUid(Mail67Activity.this), payUserContactShow1Model.getContent_id(), "0");
							al_sheding.dismiss();
						}
					});
		            //同意呢
		            Button queding=(Button)view.findViewById(R.id.queding);
		            queding.setOnClickListener(new View.OnClickListener() {
						
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
//							Intent intent=new Intent(Mail67Activity.this,Mail13_6Activity.class);
//							intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
//							startActivity(intent);
							agree(payUserContactShow1Model.getZhannei_Id(), Utils.getUid(Mail67Activity.this), payUserContactShow1Model.getContent_id(), "1");
							al_sheding.dismiss();
						}
					});
		            
		            
//		            et_feiyong.setText(); 
					al_sheding=new AlertDialog.Builder(Mail67Activity.this).setView(view).show();
				}
			});
			shedingzhixunfei.setVisibility(View.VISIBLE);
			this.findViewById(R.id.delete).setVisibility(View.GONE);
		}
		
	}
	/**
     * 有咨询费，答方设定咨询费后，问方选择同意不同意操作----POST
     * @param $zhaneniId   站内信ID
     * @param $uid  登录用户（问方）
     * @param $reply_id 回复的是哪一条用户消息ID
     * @param $is_agree  问方是否同意  0：否 1：是
     */
	private void agree(String zhaneniId,String uid,String reply_id,String is_agree)
	{
		if(is_agree.equals("1"))
		{
			isAgree=true;
		}
		else
		{
			isAgree=false;
		}
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("zhaneniId", zhaneniId);
		map.put("uid", uid);
		map.put("reply_id", reply_id);
		map.put("is_agree", is_agree);
		
		CommonUtils.CommomPostfunction(Mail67Activity.this, Constants.BadiUrl_1+"/"+"inform/agree", map, mhandler, 1, 3, 2, 4);
	}
	
	
	
}
